home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7194 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. Newsgroups: comp.lang.c
  3. Subject: Re: fwrite help?
  4. Message-ID: <danpop.824668361@rscernix>
  5. From: danpop@mail.cern.ch (Dan Pop)
  6. Date: 18 Feb 96 18:32:41 GMT
  7. References: <4fmaig$7of@news.global1.net> <harmon.824165113@pegasus.montclair.edu>
  8. Organization: CERN European Lab for Particle Physics
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <harmon.824165113@pegasus.montclair.edu> harmon@pegasus.montclair.edu (Derek Harmon) writes:
  13.  
  14. >first element in line, sizeof(char) for size insures compatibility on machines
  15. >where a character is more than one byte,
  16.  
  17. Nonsense.  sizeof(char) is 1 _by definition_.  The real reason behind
  18. writing sizeof(char) is to improve the readability of the code for the
  19. human reader.  To the compiler, sizeof(char) and 1 are equivalent in most
  20. contexts (they have the same value, but different types).
  21. >
  22. >: fwrite( line, sizeof(char), 8, fp);
  23. >
  24. >   Of course, when they are contiguous in an array, and you know the sizeof a
  25. >char is 1 byte, it's much more efficient to say you want to write an 8-byte
  26. >block of memory once, instead of a 1-byte block of memory eight times.
  27.  
  28. More nonsense.  What makes one method much more efficient than the other?
  29. I couldn't find anything in the C standard to support this claim.
  30.  
  31. If they succeed, both forms are equivalent.  In case of failure, the first
  32. form will tell you how many bytes could be successfully written to the
  33. file while the second call won't be able to provide this information.
  34.  
  35. Dan 
  36. --
  37. Dan Pop
  38. CERN, CN Division
  39. Email: danpop@mail.cern.ch 
  40. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  41.